<?php

class EmbeddedRouter extends TraitOwner
{
	public function __construct( )
	{
		$this->Module = 'System/HTML';
		$this->Traits[] = new PHPXLoadableTrait( ); // this makes the class able to instantiate from a phpx file
		$this->InitTraits( ); // activates the traits
		$this->InitPHPX( ); // activates the PHPXLoadableTrait
	}
	
	public function Init( )
	{
		// @this function needs to be in place for the PHPX to create the component
		// it should function like the constructor of a 'normal' class
		ob_start( );
		$ParentRouter = Routers::$ActiveRouter;
		if( isset( $this->RouterName ) )
		{
			if( isset( $this->RouterPath ) )
			{
				Routers::$ActiveRouter = new Router( $this->RouterPath );
			}
			else if( isset( $this->RouterModule ) )
			{
				Routers::$ActiveRouter = new Router( Modules::$Modules[$this->RouterModule]->Path . '/WWW' );
			}	
			Routers::$Routers[$this->RouterName] = Routers::$ActiveRouter;
			Routers::$ActiveRouter->Route( $ParentRouter->RemainingPath );
			Routers::$ActiveRouter = $ParentRouter;	
		}
		$this->Content = ob_get_clean();
	}
	
	// this function is called from the Router when encountering a phpx file
	public function Render( )
	{
		print $this->Content;
	}
}